<?
    /**
     * PrincipioLab
     *
     * @package    PrincipioLab
     */

    /**
     * PrincipioLab_Validate_Decorator
     *
     * @package    PrincipioLab\Validate
     */
    class PrincipioLab_Validate_Decorator extends Zend_Validate_Abstract
    {
        private $validate_interface;
        private $field_label;


        public function __construct(Zend_Validate_Interface $validate_interface, $field_label)
        {
            $this->field_label = $field_label;
            $this->validate_interface = $validate_interface;
        }


        public function isValid($value, $context = null)
        {
            $is_valid = $this->validate_interface->isValid($value, $context);

            if (!$is_valid)
            {
                foreach ($this->getMessages() as $message)
                    PrincipioLab_Messages::error($message);
            };

            return $is_valid;
        }


        public function getMessages()
        {
            return str_replace("%field_label%", $this->field_label, $this->validate_interface->getMessages());
        }
    };
?>